<?php

// +----------------------------------------------------------------------
// | TAODUDU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------

namespace Libs;

class Logs {

    private $logInfo = array(
        'cols' => array('author', 'action', 'content'),
    );
    
    
    /**
     * @package 向数据库写入Log
     * @param $type string 
     * @param $logs array 日志内容
     * @return bool  操作结果
     */
    public function write($logs = array()){
        $logInfo = $this->logInfo;
        $content['datetime'] = NOW_TIME;
        $content['ip'] = get_client_ip();
        $content['manager_id'] = session('manager_id');
        foreach ($logInfo['cols'] as $key => $val) {
            $content[$val] = isset($logs[$val]) ? $logs[$val] : isset($logs[$key]) ? $logs[$key] : '';
        }
        return $this->writes($content);
    }
    
    
    /**
     * @package 向数据库写入Log
     * @param array  log数据
     * @author Terry<admin@huicms.cn>
     * @date 2013-08-28 
     * @return bool  操作结果
     */
    public function writes($logs = array()){
        if(!is_array($logs) || empty($logs)){
            throw new Exception('the $logs parms must be array');
        }
        $result = M('memberLogs')->add($logs);
        if(FALSE !== $result){
            return true;
        }else{
            return false;
        }
    }

    
}
